package com.ellricky.baselib.ui.msg;

import android.os.Bundle;
import android.view.View;

import com.andr.common.http.callback.BaseCallback;
import com.andr.common.ui.adapter.BaseRecyclerAdapter;
import com.andr.common.ui.mvp.BasePresenter;
import com.andr.common.widget.refresh.RefreshFlag;
import com.ellricky.baselib.adapter.MsgTipAdapter;
import com.ellricky.baselib.entity.MsgTipEntity;
import com.ellricky.baselib.http.callback.EListCallback;
import com.ellricky.baselib.ui.base.BaseRefreshFragment;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import static com.ellricky.baselib.http.Api.API_MSG_BIRTH;
import static com.ellricky.baselib.http.Api.API_MSG_XU_FEI;

/**
 * 生日 or 续费
 */
public class MsgTipChildFragment extends BaseRefreshFragment<Void, BasePresenter<Void>, MsgTipEntity> {

    private int index;

    public static MsgTipChildFragment newInstance(int index) {
        MsgTipChildFragment fragment = new MsgTipChildFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("index", index);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public void initUIView(View view) {
        index = Objects.requireNonNull(getArguments()).getInt("index");
        super.initUIView(view);
        hideToolBar();
    }

    @Override
    public void setRefreshListener() {
        rvView.init(this, RefreshFlag.NONE);
    }

    @Override
    protected void initParamMap() {
        paramMap = new HashMap<>();
    }

    @Override
    protected BaseCallback getResponseCallback() {
        return new EListCallback<MsgTipEntity>(mContext) {

            @Override
            protected void onSuccess(List<MsgTipEntity> data, String msg) {
                dataSource = data;
                rvView.onLoadFinish(dataSource, refresh);
            }

            @Override
            protected void onErrorCode(String code, String msg) {
                super.onErrorCode(code, msg);
                rvView.onRefreshFailed(refresh);
            }

            @Override
            public void onHttpError(String code, String msg) {
                super.onHttpError(code, msg);
                rvView.onRefreshFailed(refresh);
            }
        };
    }

    @Override
    protected BaseRecyclerAdapter<MsgTipEntity> getRvAdapter() {
        return null;
//        return new MsgTipAdapter(mConext,index);
    }

    @Override
    protected String getUrlPath() {
        if (index == 0) return API_MSG_BIRTH;
        else if (index ==1) return API_MSG_XU_FEI;
        return "";
    }

}